<template>
<iForm ref="formRef" :model="formModel" :rules="formRules" :label-width="100">
  <FormItem label="账号：">{{ orderInfo.user.account }}</FormItem>
  <FormItem label="收货人：">{{ orderInfo.user_address.name }}</FormItem>
  <FormItem label="联系电话：">{{ orderInfo.user_address.name }}</FormItem>
  <FormItem label="收件地区：">{{ orderInfo.user_address.tel }}</FormItem>
  <FormItem label="详细地址：">{{ orderInfo.user_address.address_detail }}</FormItem>
  <FormItem label="邮政编码：">{{ orderInfo.user_address.postal_code }}</FormItem>
  <FormItem label="快递公司名称" prop="company"><Input type="text" v-model="formModel.company"></Input></FormItem>
  <FormItem label="快递单号" prop="number"><Input type="text" v-model="formModel.number"></Input></FormItem>

  <FormItem><Button type="primary" long :loading="loadingSubmit" @click="onClickSubmit">确认发货</Button></FormItem>
</iForm>
</template>

<script>
import qs from 'qs';
import { Form, Button, Input, Message } from 'iview';
import ajaxiView from '@/utils/ajaxiView';
import auth from '@/utils/auth';

export default {
  props: ['currentRow'],
  components: {
    [Form.name]: Form,
    [Form.Item.name]: Form.Item,
    [Input.name]: Input,
    [Button.name]: Button
  },
  data() {
    return {
      token: auth.getToken(),
      orderInfo: this.$props.currentRow,
      loadingSubmit: false,
      formModel: {
        user_order_id: this.$props.currentRow.user_order_id,
        company: '',
        number: '',
        status: 9
      },
      formRules: {
        company: [
          {required: true, message: '快递公司不能为空!', trigger: 'blur'}
        ],
        number: [
          {required: true, message: '快递单号不能为空!', trigger: 'blur'}
        ]
      },
    };
  },
  methods: {
    onClickSubmit() {
      var _this = this;
      _this.$refs.formRef.validate((valid) => {
        if(valid) {
          _this.loadingSubmit = true;

          ajaxiView.put('/backstage/user/order/status?token='+_this.token, qs.stringify(_this.formModel)).then(function(data) {
            if(data !== false) {
              Message.success({
                content: data.msg,
                onClose: function() {
                  window.location.reload();
                }
              });
            }
          });

          _this.submitLoading = false;
        }
      });
    }
  }
};

</script>
